package ru.alt22.visor.php.ui.swt;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;

import ru.alt22.visor.php.ui.PluginImages;
import ru.alt22.visor.php.ui.views.UnitTestsView;

public class TestResultDetails extends Composite {

	private Text stack;
	private UnitTestsView view;

	public TestResultDetails(Composite parent, UnitTestsView view) {
		super(parent, SWT.NONE);
		initialize();

		this.view = view;
	}

	public void setDetails(String text) {
		stack.setText(text.replaceAll("<br />", "\n"));
	}

	private void initialize() {
		setLayout(new GridLayout(2, false));

		CLabel label = new CLabel(this, SWT.NONE);
		label.setText("Test result details");
		label.setImage(PluginImages.VIEW_DETAILS.createImage());
		label.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));

		Button button = new Button(this, SWT.FLAT);
		button.setImage(PluginImages.ACTION_CLOSE.createImage());
		button.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				TestResultDetails.this.view.hideTestDetails();
			}
		});

		stack = new Text(this, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY);
		stack.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 2, 2));
	}

}